<?php

namespace App\Admin\Controllers;

use App\Models\ExhibitorMessage;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Illuminate\Support\Facades\Hash;

class ExhibitorMessageController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '展商工作提示';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ExhibitorMessage());

        $grid->column('title', __('exhibitor_message.title'));
        $grid->column('addres', __('exhibitor_message.addres'));
        $grid->column('matters_needing_attention', __('exhibitor_message.matters_needing_attention'));
        $grid->column('contacts', __('exhibitor_message.contacts'));
        $grid->column('contact_phone', __('exhibitor_message.contact_phone'));
        $grid->column('e_mail', __('exhibitor_message.e_mail'));
        $grid->column('status', trans('exhibitor_message.status'));
        $grid->column('certificates_exhibitor_information_number', trans('exhibitor_message.certificates_exhibitor_information_number'));
        $script = <<<EOT

var search = $('.btn-dropbox');
search.hide();
EOT;
        Admin::script($script);
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(ExhibitorMessage::findOrFail($id));

        $show->field('id', __('exhibitor_message.id'));
        $show->field('title', __('exhibitor_message.title'));
        $show->field('contents', __('exhibitor_message.contents'));
        $show->field('addres', __('exhibitor_message.addres'));
        $show->field('matters_needing_attention', __('exhibitor_message.matters_needing_attention'));
        $show->field('contacts', __('exhibitor_message.contacts'));
        $show->field('contact_phone', __('exhibitor_message.contact_phone'));
        $show->field('e_mail', __('exhibitor_message.e_mail'));
        $show->field('exhibitor_time', __('exhibitor_message.exhibitor_time'));
        $show->field('certificates_exhibitor_information_number', __('exhibitor_message.certificates_exhibitor_information_number'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new ExhibitorMessage());

        $form->text('title', __('exhibitor_message.title'));
//        $form->UEditor('contents', __('exhibitor_message.contents'));

//
//        $form->table('contents', __('exhibitor_message.contents'), function ($table) {
//            $table->text('exhibition_registration_time', '展商报到时间');
//            $table->text('explosive_ordnance_disposal_exercise', '排爆演习');
//            $table->text('exhibitors_working_hours', '展商工作时间');
//        });


        $form->text('addres', __('exhibitor_message.addres'));
        $form->text('matters_needing_attention', __('exhibitor_message.matters_needing_attention'));
        $form->text('contacts', __('exhibitor_message.contacts'));


        $form->text('contact_phone', __('exhibitor_message.contact_phone'));
        $form->text('e_mail', __('exhibitor_message.e_mail'));
        $form->text('exhibitor_time', __('exhibitor_message.exhibitor_time'));
//        $form->number('certificates_exhibitor_information_number', __('exhibitor_message.certificates_exhibitor_information_number'))->min(1)->max(999)->rules('required');
        $form->saving(function (Form $form) {
            $contents= request()->get('contents');
//            dd($contents);
            $form->model()->status = 1;


        });
        $form->saved(function (Form $form) {
            return redirect('admin/exhibitor-messages/1/edit')->send();
        });
        $form->tools(function ($tools) {

            // 去掉`列表`按钮
            $tools->disableList();

            // 去掉`删除`按钮
            $tools->disableDelete();

            // 去掉`查看`按钮
            $tools->disableView();

        });
        $form->footer(function ($footer) {



            // 去掉`查看`checkbox
            $footer->disableViewCheck();

            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();

            // 去掉`继续创建`checkbox
            $footer->disableCreatingCheck();

        });
        return $form;
    }
}
